home *** CD-ROM | disk | FTP | other *** search
/ Your Choice 3 / Your Choice Software Collection 3.iso / prgmming / flames / flame_mx.c < prev    next >
C/C++ Source or Header  |  1993-08-29  |  8KB  |  237 lines

  1. //**************************************************************************
  2. //*                                                                        *
  3. //*    CFLAMES2 by Kirk A. Baum     (Modex Version *FAST*)                 *
  4. //*       This C program was addapted from a pascal program by M.D.Mackey. *
  5. //*       It has been modified to half the resolution used by Mark and the *
  6. //*       routines are in C with inline assembly.  The original code was   *
  7. //*       written in Pascal with Inline assemby for mode 13h.              *
  8. //*       As with Marks code, I release this code into the public domain.  *
  9. //*       It may be freely distributed and modified, but please give credit*
  10. //*       where it is due if you use this code in your program.            *
  11. //*       If you have any suggestions or comments please contact me at:    *
  12. //*       kbaum@Novell.com.                                                *
  13. //*       Mark can be reached at: mackey@aqueous.ml.csiro.au               *
  14. //*                                                                        *
  15. //**************************************************************************
  16.  
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <time.h>
  20. #include <conio.h>
  21.  
  22. void setmodex(void);
  23. void setpalette(void);
  24.  
  25. int p1[56][80];
  26. unsigned int i,j,k,l;
  27. int delta;
  28. char ch;
  29. unsigned char pal[768]={  0,  0,  0,  0,  0, 24,  0,  0, 24,  0,  0, 28,
  30.               0,  0, 32,  0,  0, 32,  0,  0, 36,  0,  0, 40,
  31.                8,  0, 40, 16,  0, 36, 24,  0, 36, 32,  0, 32,
  32.               40,  0, 28, 48,  0, 28, 56,  0, 24, 64,  0, 20,
  33.               72,  0, 20, 80,  0, 16, 88,  0, 16, 96,  0, 12,
  34.              104,  0,  8,112,  0,  8,120,  0,  4,128,  0,  0,
  35.              128,  0,  0,132,  0,  0,136,  0,  0,140,  0,  0,
  36.              144,  0,  0,144,  0,  0,148,  0,  0,152,  0,  0,
  37.              156,  0,  0,160,  0,  0,160,  0,  0,164,  0,  0,
  38.              168,  0,  0,172,  0,  0,176,  0,  0,180,  0,  0,
  39.              184,  4,  0,188,  4,  0,192,  8,  0,196,  8,  0,
  40.              200, 12,  0,204, 12,  0,208, 16,  0,212, 16,  0,
  41.              216, 20,  0,220, 20,  0,224, 24,  0,228, 24,  0,
  42.              232, 28,  0,236, 28,  0,240, 32,  0,244, 32,  0,
  43.              252, 36,  0,252, 36,  0,252, 40,  0,252, 40,  0,
  44.              252, 44,  0,252, 44,  0,252, 48,  0,252, 48,  0,
  45.              252, 52,  0,252, 52,  0,252, 56,  0,252, 56,  0,
  46.              252, 60,  0,252, 60,  0,252, 64,  0,252, 64,  0,
  47.              252, 68,  0,252, 68,  0,252, 72,  0,252, 72,  0,
  48.              252, 76,  0,252, 76,  0,252, 80,  0,252, 80,  0,
  49.              252, 84,  0,252, 84,  0,252, 88,  0,252, 88,  0,
  50.              252, 92,  0,252, 96,  0,252, 96,  0,252,100,  0,
  51.              252,100,  0,252,104,  0,252,104,  0,252,108,  0,
  52.              252,108,  0,252,112,  0,252,112,  0,252,116,  0,
  53.              252,116,  0,252,120,  0,252,120,  0,252,124,  0,
  54.              252,124,  0,252,128,  0,252,128,  0,252,132,  0,
  55.              252,132,  0,252,136,  0,252, 136,   0,252, 140,   0,
  56.              252, 140,   0,252, 144,   0,252, 144,   0,252, 148,   0,
  57.              252, 152,   0,252, 152,   0,252, 156,   0,252, 156,   0,
  58.              252, 160,   0,252, 160,   0,252, 164,   0,252, 164,   0,
  59.              252, 168,   0,252, 168,   0,252, 172,   0,252, 172,   0,
  60.              252, 176,   0,252, 176,   0,252, 180,   0,252, 180,   0,
  61.              252, 184,   0,252, 184,   0,252, 188,   0,252, 188,   0,
  62.              252, 192,   0,252, 192,   0,252, 196,   0,252, 196,   0,
  63.              252, 200,   0,252, 200,   0,252, 204,   0,252, 208,   0,
  64.              252, 208,   0,252, 208,   0,252, 208,   0,252, 208,   0,
  65.              252, 212,   0,252, 212,   0,252, 212,   0,252, 212,   0,
  66.              252, 216,   0,252, 216,   0,252, 216,   0,252, 216,   0,
  67.              252, 216,   0,252, 220,   0,252, 220,   0,252, 220,   0,
  68.              252, 220,   0,252, 224,   0,252, 224,   0,252, 224,   0,
  69.              252, 224,   0,252, 228,   0,252, 228,   0,252, 228,   0,
  70.              252, 228,   0,252, 228,   0,252, 232,   0,252, 232,   0,
  71.              252, 232,   0,252, 232,   0,252, 236,   0,252, 236,   0,
  72.              252, 236,   0,252, 236,   0,252, 240,   0,252, 240,   0,
  73.              252, 240,   0,252, 240,   0,252, 240,   0,252, 244,   0,
  74.              252, 244,   0,252, 244,   0,252, 244,   0,252, 248,   0,
  75.              252, 248,   0,252, 248,   0,252, 248,   0,252, 252,   0,
  76.              252, 252,   4,252, 252,   8,252, 252,  12,252, 252,  16,
  77.              252, 252,  20,252, 252,  24,252, 252,  28,252, 252,  32,
  78.              252, 252,  36,252, 252,  40,252, 252,  40,252, 252,  44,
  79.              252, 252,  48,252, 252,  52,252, 252,  56,252, 252,  60,
  80.              252, 252,  64,252, 252,  68,252, 252,  72,252, 252,  76,
  81.              252, 252,  80,252, 252,  84,252, 252,  84,252, 252,  88,
  82.              252, 252,  92,252, 252,  96,252, 252, 100,252, 252, 104,
  83.              252, 252, 108,252, 252, 112,252, 252, 116,252, 252, 120,
  84.              252, 252, 124,252, 252, 124,252, 252, 128,252, 252, 132,
  85.              252, 252, 136,252, 252, 140,252, 252, 144,252, 252, 148,
  86.              252, 252, 152,252, 252, 156,252, 252, 160,252, 252, 164,
  87.              252, 252, 168,252, 252, 168,252, 252, 172,252, 252, 176,
  88.              252, 252, 180,252, 252, 184,252, 252, 188,252, 252, 192,
  89.              252, 252, 196,252, 252, 200,252, 252, 204,252, 252, 208,
  90.              252, 252, 208,252, 252, 212,252, 252, 216,252, 252, 220,
  91.              252, 252, 224,252, 252, 228,252, 252, 232,252, 252, 236,
  92.              252, 252, 240,252, 252, 244,252, 252, 248,252, 252, 252};
  93.  
  94.  
  95. //************************************************************************
  96. //*************************************************************************
  97. void setmodex()
  98. {
  99. asm CLD
  100. asm MOV AX,13h
  101. asm INT 10h
  102. asm CLI
  103. asm MOV DX,3c4h
  104. asm MOV AX,604h;//                 ; "Unchain my heart". And my VGA...
  105. asm OUT DX,AX
  106. asm MOV AX,0F02h;//                ; All planes
  107. asm OUT DX,AX
  108.  
  109. asm MOV DX,3D4h
  110. asm MOV AX,14h;//                  ; Disable dword mode
  111. asm OUT DX,AX
  112. asm MOV AX,0E317h;//               ; Enable byte mode.
  113. asm OUT DX,AX
  114. asm MOV AL,9
  115. asm OUT DX,AL
  116. asm INC DX
  117. asm IN  AL,DX
  118. asm AND AL,0E0h;//                 ; Duplicate each scan 8 times.
  119. asm ADD AL,7
  120. asm OUT DX,AL
  121. }
  122.  
  123.  
  124. //*************************************************************************
  125. //*************************************************************************
  126. void setpalette()
  127. {
  128. int  i;
  129.  
  130. for(i=0;i<768;i++)
  131.    {
  132.    pal[i] = pal[i] >> 2;
  133.    }
  134.  
  135.  _SI = (unsigned int)&pal[0];
  136.  asm mov cx,768
  137.  asm mov dx,0x03c8
  138.  asm xor al,al
  139.  asm out dx,al
  140.  asm inc dx
  141. l1:
  142.  asm outsb
  143.  asm dec cx
  144.  asm jnz l1
  145. }
  146.  
  147.  
  148. //*************************************************************************
  149. //*************************************************************************
  150. void main()
  151. {
  152.   setmodex();
  153.   setpalette();
  154.   randomize();
  155.   ch=' ';
  156.  
  157.   // Initialize the screen buffer
  158.   for(i=0;i<56;i++)
  159.      {
  160.      for(j=0;j<80;j++)
  161.     {
  162.     p1[i][j]=0;
  163.     }
  164.      }
  165.  
  166.   // Loop until the escape key has been pressed
  167.   while(ch != 27)
  168.      {
  169.  
  170.      // transform the current buffer
  171.      asm mov cx,4399;
  172.      _DI = (unsigned int)&p1[0][0];
  173.      asm xor ax,ax
  174.      asm add di,160
  175. D1:
  176.      asm mov ax,ds:[di-2]
  177.      asm add ax,ds:[di]
  178.      asm add ax,ds:[di+2]
  179.      asm add ax,ds:[di+160]
  180.      asm shr ax,2
  181.      asm jz D2
  182.  
  183.      asm sub ax,1
  184.      asm jz D2
  185.      asm sub ax,1
  186.      asm jz D2
  187.      asm sub ax,1
  188.  
  189. D2:
  190.      asm mov word ptr ds:[di-160],ax
  191.      asm add di,2
  192.      asm dec cx
  193.      asm jnz D1;
  194.  
  195.  
  196.      // Set new bottom line with random white or black color
  197.      delta = 0;
  198.      for(j=0;j<80;j++)   // {set new bottom line}
  199.     {
  200.     if(random(10) < 5)
  201.       {
  202.       delta=random(2)*255;
  203.       }
  204.     p1[54][j]=delta;
  205.     p1[55][j]=delta;
  206.     }
  207.  
  208.  
  209.      // Write buffer to the screen
  210.      _SI = (unsigned int)&p1[0][0];
  211.      asm mov di,0
  212.      asm mov ax,0A000h
  213.      asm mov es,ax
  214.      asm mov cx,40*50
  215. F1:
  216.      asm mov ax,ds:[si]
  217.      asm add si,2
  218.      asm mov dl,al
  219.      asm mov ax,ds:[si]
  220.      asm add si,2
  221.      asm mov dh,al
  222.      asm mov es:[di],dx
  223.      asm add di,2
  224.      asm dec cx
  225.      asm jnz F1
  226.  
  227.  
  228.      if(kbhit())
  229.        {
  230.        ch=getch();
  231.        }
  232.      }
  233.  
  234.   // Restore the screen to text mode
  235.   asm mov ax,03h
  236.   asm int 10h
  237. }